package com.jindi.appuser.service.impl;

import com.jindi.appuser.common.EmptyUtil;
import com.jindi.appuser.common.ServerResponse;
import com.jindi.appuser.dao.AppMapper;
import com.jindi.appuser.domain.App;
import com.jindi.appuser.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppServiceImpl implements AppService {
    @Autowired
    private AppMapper appMapper;
    @Override
    public ServerResponse getPrice(String os) {
        App app = appMapper.selectByOs(os);
        return ServerResponse.createBySuccess(app);
    }

    public static void main(String[] args) {
        String aa = "12321";
        String json = "{\"code\",\""+aa+"\"}";
        System.out.println(json);
    }

    @Override
    public ServerResponse closeDrow(String doType) {
        if(EmptyUtil.isEmpty(doType) || (!"1".equals(doType) && !"2".equals(doType))){
            return ServerResponse.createByErrorMessage("参数错误");
        }
        App app = appMapper.selectByPrimaryKey(1);
        app.setDrowStatus(doType);
        Integer index  = appMapper.updateByPrimaryKeySelective(app);
        if(index>0){
            return ServerResponse.createBySuccess("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

    @Override
    public ServerResponse info() {
        return ServerResponse.createBySuccess(appMapper.selectByPrimaryKey(1));
    }

    @Override
    public ServerResponse update(App app) {
        if(EmptyUtil.isEmpty(app.getPrice())
                && EmptyUtil.isEmpty(app.getQq())
                && EmptyUtil.isEmpty(app.getDrowStatus())
                &&EmptyUtil.isEmpty(app.getEmail())){
            return ServerResponse.createByErrorMessage("参数错误");
        }
        Integer index = appMapper.updateByPrimaryKeySelective(app);
        if(index>0){
            return ServerResponse.createBySuccess("修改成功");
        }
        return ServerResponse.createByErrorMessage("修改失败");
    }
}
